package logic

import (
	"context"
	"goods-mngr/goodsrpc/goodsrpc"
	"goods-mngr/goodsrpc/internal/svc"
	"goods-mngr/goodsrpc/model"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateLogic {
	return &UpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateLogic) Update(in *goodsrpc.UpdateRequest) (*goodsrpc.UpdateResponse, error) {
	// todo: add your logic here and delete this line

	shop := model.Shop{

		Name:  in.Name,
		Price: float64(in.Price),
		Num:   int(in.Num),
	}
	model.DB.Debug().Updates(&shop)
	return &goodsrpc.UpdateResponse{
		Id: int64(shop.ID),
	}, nil
}
